package com.cy.demo.controller;

import com.cy.demo.pojo.Address;
import com.cy.demo.pojo.Order;
import com.cy.demo.service.IAddressService;
import com.cy.demo.service.IOrderService;
import com.cy.demo.utils.jsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RequestMapping("orders")
@RestController
public class OrderController extends BaseController{

    @Autowired
    private IOrderService orderService;

    @RequestMapping("create")
    public jsonResult<Order> create(int aid, int[] cids, HttpSession session) throws Exception {
        // 从Session中取出uid和username
        Integer uid = getuidFromSession(session);
        String username = getUsernameFromSession(session);
        // 调用业务对象执行业务
        Order data = orderService.create(aid, cids, uid, username);
        // 返回成功与数据
        return new jsonResult<Order>(data, OK);
    }
}
